#include "../game_server.cpp"
#include "../room.cpp"
#include "../user.cpp"
#include "../protocol_dist.hpp"
#include "ws_websocket.hpp"
#include <iostream>

using namespace std;
FASTDO_API void ActionMain(ProtocolC2SLeaveRoom *msg, pWsReqCtx ctx, GameServer &game)
{
    ProtocolS2CLeaveRoom rtn;
    auto user = game.getUser(ctx);
    if (user != nullptr)
    {
        auto room = game.getRoomByUser(user);
        if (room != nullptr)
        {
            room->userLeave(user);
            rtn.ok = true;
        }
    }
    ctx->send(ws::OpCode::dataText, false, rtn.toMixed().json());
}